package com.zhanghp.demo01.generic.fundament;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhanghp
 * @date 2022-08-26 14:36
 */
public abstract class Publisher<O extends PublisherObserver<A>, A> {

    private final List<O> OBSERVERS;

    public Publisher() {
        OBSERVERS = new ArrayList<>();
    }

    public void add(O obs) {
        OBSERVERS.add(obs);
    }

    public void remove(O obs) {
        OBSERVERS.remove(obs);
    }

    public void notifyObservers(A argument) {
        for (var obs : OBSERVERS) {
            obs.update(argument);
        }
    }
}
